//
//  TGAlertView.m
//  PlayBall
//
//  Created by Jdd‘s macbook on 13-10-15.
//
//

#import "JddTGAlertView.h"
#import "JddUserProfile.h"
#import "JddViewControllerManager.h"

@implementation JddTGAlertView
GET_INSTANCE_VIEW_IMPLEMENT(JddTGAlertView)

-(void)alertMessage:(NSString*)Message{
    self.type = 1;
    self.message.text = Message;
    if ([Message rangeOfString:@"余额不足"].location != NSNotFound) {
        self.type = 0;//余额不足
        self.label1.text = @"充值";
        self.label2.text = @"取消";
        self.label6.text = @"玩球球";
        self.message.hidden = NO;
        [self loadContentView ];
        [self show];
    }else if ([Message isEqualToString:@"认购成功"]) {
        self.label6.text = Message;
        [JddCommonFunction setWaitingViewHidden:NO fromController:self.fromview];
        //请求得到余额
        JddQueryUserInfoOperation *operation = [[JddQueryUserInfoOperation alloc] init];
        operation.delegate = self;
        [[JddGlobalParameter sharedInstance].operationQueue addOperation:operation];
    }else{
        [self loadContentView ];
        [self show];
    }
}

- (void)QueryUserInfoOperationResult:(NSData *)result{
    [JddCommonFunction setWaitingViewHidden:YES fromController:self.fromview];
    if (result) {
        if ([JddDataParser parseUserInfoResult:result]) {
            self.label3.hidden = NO;
            self.label4.hidden = NO;
            self.label5.hidden = NO;
            self.label7.hidden = NO;
            //合买
            NSString *string1= [NSString stringWithFormat:@"第%@期",self.lssueString];
            self.label3.text = [NSString stringWithFormat:@"方案金额：%@",self.faMoney];
            self.label7.text = [NSString stringWithFormat:@"发起%@%@购买方案",self.typestring,string1];
            self.label4.text = [NSString stringWithFormat:@"认购金额：%@",self.moneylable];
            self.label5.text = [NSString stringWithFormat:@"账户余额：%@彩豆",[JddUserProfile sharedInstance].balance];
            self.message.hidden = YES;
            self.label2.text = @"购彩记录";
        }
    }
    [self loadContentView ];
    [self show];
}

- (void)loadContentView{
    _contentView = [JddTGAlertView getInstanceView];
}

//第1按钮事件
-(IBAction)selectButton1:(id)sender{
    [self dismissAnimated:YES];
    //支付宝jdd_cz
    switch (self.type) {
        case 0:
            [[JddViewControllerManager sharedInstance] pushViewControllerWithIndex:CONTROLLER_SELECT_RECHARGE_WAY
                                                                 fromController:self.fromview
                                                                     withObject:nil
                                                                    withObject2:nil];
            break;
        case 1:
            [self.delegate performSelector:@selector(tbuy)];
            break;
        default:
            break;
    }
}

//第2按钮事件
-(IBAction)selectButton2:(id)sender{
    [self dismissAnimated:YES];
    if (self.type == 1) {
        [[JddViewControllerManager sharedInstance] pushViewControllerWithIndex:CONTROLLER_BUY_HISTORY
                                                             fromController:self.fromview
                                                                 withObject:nil
                                                                withObject2:nil];
    }
}

@end


